import Vue from 'vue'
import Vuex from 'vuex'
import http from '@/util/http'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  plugins:[createPersistedState({
    reducer:(state)=>{
      return {
        cityId:state.cityId,
        cityName:state.cityName
      }
    }
  })],
  state:{
    cityId:420100,
    cityName:'武汉',
    cinemaslist:[],
    nowCityId:420100,
    lastCityId:420100,
    isTabbarShow:true
  },

  actions:{
    getCity(store){
      return http({
          url:`/gateway?cityId=${store.state.cityId}&ticketFlag=1&k=2068065`,
          headers:{
              'X-Host': 'mall.film-ticket.cinema.list'
          }
      }).then(res=>{
          console.log(res.data.data.cinemas)
          store.state.cinemaslist = res.data.data.cinemas
          store.state.lastCityId = store.state.nowCityId
      })
    }
  },

  mutations:{
    changeCity(state,name){
      console.log(state,name)
      state.nowCityId =name.id
      state.cityId = name.id
      state.cityName = name.name
    },
    hide(state){
      state.isTabbarShow = false
    },
    show(state){
      state.isTabbarShow = true
    }
  }
})
